package com.ly.heart.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.heart.domain.FileEntity;
import com.ly.heart.domain.SurveyRefereeCompanyEntity;
import com.ly.heart.mapper.SurveyRefereeCompanyMapper;
import com.ly.heart.service.IFileInfoService;
import com.ly.heart.service.ISurveyRefereeCompanyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 路条人/合作方公司主体Service业务层处理
 * @author wutao
 * @date 2024-05-24
 */
@Service
public class SurveyRefereeCompanyServiceImpl extends ServiceImpl<SurveyRefereeCompanyMapper, SurveyRefereeCompanyEntity> implements ISurveyRefereeCompanyService {

    @Resource
    private SurveyRefereeCompanyMapper erpSurveyRefereeCompanyInfoMapper;
    @Resource
    private IFileInfoService iFileInfoService;

    /**
     * 查询路条人/合作方公司主体
     * @param id 路条人/合作方公司主体ID
     * @return 路条人/合作方公司主体
     */
    @Override
    public SurveyRefereeCompanyEntity selectErpSurveyRefereeCompanyInfoById (String id) {
        return erpSurveyRefereeCompanyInfoMapper.selectErpSurveyRefereeCompanyInfoById ( id );
    }

    /**
     * 查询路条人/合作方公司主体列表
     * @param erpSurveyRefereeCompanyInfo 路条人/合作方公司主体
     * @return 路条人/合作方公司主体
     */
    @Override
    public List<SurveyRefereeCompanyEntity> selectErpSurveyRefereeCompanyInfoList (SurveyRefereeCompanyEntity erpSurveyRefereeCompanyInfo) {
        List<SurveyRefereeCompanyEntity> surveyRefereeCompanyEntities = erpSurveyRefereeCompanyInfoMapper.selectErpSurveyRefereeCompanyInfoList ( erpSurveyRefereeCompanyInfo );
        for ( SurveyRefereeCompanyEntity surveyRefereeCompanyEntity : surveyRefereeCompanyEntities ) {
            List<FileEntity> fileEntities = iFileInfoService.list ( new QueryWrapper<FileEntity> ().eq ( "relationId", surveyRefereeCompanyEntity.getId () ) );
            surveyRefereeCompanyEntity.setFileEntities ( fileEntities );
        }
        return surveyRefereeCompanyEntities;
    }

    /**
     * 新增路条人/合作方公司主体
     * @param erpSurveyRefereeCompanyInfo 路条人/合作方公司主体
     * @return 结果
     */
    @Override
    public int insertErpSurveyRefereeCompanyInfo (SurveyRefereeCompanyEntity erpSurveyRefereeCompanyInfo) {
        erpSurveyRefereeCompanyInfo.setCreateTime ( DateUtils.getNowDate () );
        return erpSurveyRefereeCompanyInfoMapper.insertErpSurveyRefereeCompanyInfo ( erpSurveyRefereeCompanyInfo );
    }

    /**
     * 修改路条人/合作方公司主体
     * @param erpSurveyRefereeCompanyInfo 路条人/合作方公司主体
     * @return 结果
     */
    @Override
    public int updateErpSurveyRefereeCompanyInfo (SurveyRefereeCompanyEntity erpSurveyRefereeCompanyInfo) {
        erpSurveyRefereeCompanyInfo.setUpdateTime ( DateUtils.getNowDate () );
        return erpSurveyRefereeCompanyInfoMapper.updateErpSurveyRefereeCompanyInfo ( erpSurveyRefereeCompanyInfo );
    }

    @Override
    public int updateRefereeCompanyByRefereeId (SurveyRefereeCompanyEntity surveyRefereeCompanyEntity) {
        surveyRefereeCompanyEntity.setUpdateTime ( DateUtils.getNowDate () );
        //surveyRefereeCompanyEntity.setUpdateBy ( SecurityUtils.getLoginUser ().getUser ().getUserId () );
        return erpSurveyRefereeCompanyInfoMapper.updateRefereeCompanyByRefereeId ( surveyRefereeCompanyEntity );
    }

    /**
     * 批量删除路条人/合作方公司主体
     * @param ids 需要删除的路条人/合作方公司主体ID
     * @return 结果
     */
    @Override
    public int deleteErpSurveyRefereeCompanyInfoByIds (String[] ids) {
        return erpSurveyRefereeCompanyInfoMapper.deleteErpSurveyRefereeCompanyInfoByIds ( ids );
    }

    /**
     * 删除路条人/合作方公司主体信息
     * @param id 路条人/合作方公司主体ID
     * @return 结果
     */
    @Override
    public int deleteErpSurveyRefereeCompanyInfoById (String id) {
        return erpSurveyRefereeCompanyInfoMapper.deleteErpSurveyRefereeCompanyInfoById ( id );
    }
}
